﻿//-----------------------------------------------------------------------------
// File: HScrollBar.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Text;
using System.ComponentModel;
using System.Drawing.Design;

namespace Cerebrum.Direct3D.Forms.Scrolling
{
    /// <summary>
    /// Элемент управления ScrollBar
    /// </summary>
    public class HScrollBar : Cerebrum.Direct3D.Forms.Control
    {
        public event System.EventHandler ValueChanged;
        public event System.Windows.Forms.ScrollEventHandler Scroll;

        #region Переменные
        private Cerebrum.Direct3D.Forms.ScrollBar liteHScrolBar1;
        private Cerebrum.Direct3D.Forms.ImageButton btnLeft;
        private Cerebrum.Direct3D.Forms.ImageButton btnRight;
        private Cerebrum.Direct3D.Forms.ImageButton crawlFill;
        private Cerebrum.Direct3D.Forms.ImageButton crawlLeft;
        private Cerebrum.Direct3D.Forms.ImageButton crawlRight;
        private Cerebrum.Direct3D.Forms.Control crawl;
        #endregion

        #region Конструкторы
        /// <summary>
        /// Конструктор класса ScrollBar.
        /// </summary>
        public HScrollBar()
        {
            this.Size = new System.Drawing.SizeF(16, 300);
            // Создаём элементы управления.
            btnLeft = new Cerebrum.Direct3D.Forms.ImageButton();
            btnRight = new Cerebrum.Direct3D.Forms.ImageButton();
            liteHScrolBar1 = new ScrollBar();
			liteHScrolBar1.Direction = LayoutDirection.Horizontal;
            crawlLeft = new Cerebrum.Direct3D.Forms.ImageButton();
            crawlRight = new Cerebrum.Direct3D.Forms.ImageButton();
            crawlFill = new Cerebrum.Direct3D.Forms.ImageButton();
            crawl = new Control();
            // Настройки кнопки Left.
            btnLeft.Location = new System.Drawing.PointF(0, 0);
            btnLeft.Size = new System.Drawing.SizeF(16, this.Size.Height);
            btnLeft.Dock = System.Windows.Forms.DockStyle.Left;
            btnLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(btnLeft_MouseDown);
            btnLeft.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.btnLeft.ToBitmap();
            // Настройки кнопки Right.
            btnRight.Location = new System.Drawing.PointF(this.Size.Width - btnRight.Size.Width, 0);
            btnRight.Size = new System.Drawing.SizeF(16, this.Size.Height);
            btnRight.Dock = System.Windows.Forms.DockStyle.Right;
            btnRight.MouseDown += new System.Windows.Forms.MouseEventHandler(btnRight_MouseDown);
            btnRight.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.btnRight.ToBitmap();
            // Настраиваем ползунок.
            liteHScrolBar1.Location = new System.Drawing.PointF(0, 20);
            liteHScrolBar1.Dock = System.Windows.Forms.DockStyle.Fill;
            liteHScrolBar1.SizableCrawler = true;
            liteHScrolBar1.ValueChanged += new EventHandler(liteHScrolBar1_ValueChanged);
            liteHScrolBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(liteHScrolBar1_Scroll);
            // Настраиваем ползунок.
            crawlLeft.Location = new System.Drawing.PointF(0, 0);
            crawlLeft.Size = new System.Drawing.SizeF(5, 16);
            crawlLeft.Transparent = true;
            crawlLeft.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.CrawlLeft.ToBitmap();
            crawlLeft.Dock = System.Windows.Forms.DockStyle.Left;

            crawlRight.Location = new System.Drawing.PointF(0, 0);
            crawlRight.Size = new System.Drawing.SizeF(5, 16);
            crawlRight.Transparent = true;
            crawlRight.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.CrawlRight.ToBitmap();
            crawlRight.Dock = System.Windows.Forms.DockStyle.Right;

            crawlFill.Location = new System.Drawing.PointF(0, 0);
            crawlFill.Size = new System.Drawing.SizeF(16, 16);
            crawlFill.Transparent = true;
            crawlFill.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.CrawlHFill.ToBitmap();
            crawlFill.Dock = System.Windows.Forms.DockStyle.Fill;

            crawl.Controls.Add(crawlFill);
            crawl.Controls.Add(crawlRight);
            crawl.Controls.Add(crawlLeft);

            liteHScrolBar1.CrawlerControl = crawl;
            // Добавляем их на HScrollBar.
            this.Controls.Add(liteHScrolBar1);
            this.Controls.Add(btnRight);
            this.Controls.Add(btnLeft);
        }
        #endregion

        #region Обработчики событий
        /// <summary>
        /// Обработчик события нажатия кнопки для перемещения на строку вверх на ScrollBar-е.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRight_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            liteHScrolBar1.ButtonClick(ScrollBarButtons.SmallIncrement);
        }

        /// <summary>
        /// Обработчик события нажатия кнопки для перемещения на строку вниз на ScrollBar-е.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLeft_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            liteHScrolBar1.ButtonClick(ScrollBarButtons.SmallDecrement);
        }

        /// <summary>
        /// Передаём событие дальше.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void liteHScrolBar1_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
        {
            if (Scroll != null)
            {
                Scroll(this, e);
            }
        }

        /// <summary>
        /// Передаём событие дальше.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void liteHScrolBar1_ValueChanged(object sender, EventArgs e)
        {
            if (ValueChanged != null)
            {
                ValueChanged(this, e);
            }
        }
        #endregion

        #region Интерфейс
        /// <summary>
        /// Нажатие кнопки.
        /// </summary>
        /// <param name="btn">Какая кнопка нажимается.</param>
        public void ButtonClick(ScrollBarButtons btn)
        {
            liteHScrolBar1.ButtonClick(btn);
        }

        /// <summary>
        /// Начальное значение шкалы.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(0),
            Description("Начальное значение шкалы")
        ]
        public float Minimum
        {
            set
            {
                liteHScrolBar1.Minimum = value;
            }
            get
            {
                return liteHScrolBar1.Minimum;
            }
        }

        /// <summary>
        /// Конечное значение шкалы.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(1000),
            Description("Конечное значение шкалы")
        ]
        public float Maximum
        {
            set
            {
                liteHScrolBar1.Maximum = value;
            }
            get
            {
                return liteHScrolBar1.Maximum;
            }
        }

        /// <summary>
        /// Минимальное перемещение ползунка.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(10),
            Description("Минимальное перемещение ползунка")
        ]
        public float SmallChange
        {
            set
            {
                liteHScrolBar1.SmallChange = value;
            }
            get
            {
                return liteHScrolBar1.SmallChange;
            }
        }

        /// <summary>
        /// Максимальное перемещение ползунка.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(100),
            Description("Максимальное перемещение ползунка")
        ]
        public float LargeChange
        {
            set
            {
                liteHScrolBar1.LargeChange = value;
            }
            get
            {
                return liteHScrolBar1.LargeChange;
            }
        }

        /// <summary>
        /// Значение (позиция).
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(0),
            Description("Значение (позиция)")
        ]
        public float Value
        {
            set
            {
                liteHScrolBar1.Value = value;
            }
            get
            {
                return liteHScrolBar1.Value;
            }
        }

        /// <summary>
        /// Вариант возвращения значения в свойстве Value
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(0),
            Description("Вариант возвращения значения в свойстве Value")
        ]
        public Cerebrum.Direct3D.Forms.ScrollingMethodEnum MathMethod
        {
            set
            {
				liteHScrolBar1.ScrollingMethod = value;
            }
            get
            {
				return liteHScrolBar1.ScrollingMethod;
            }
        }

        /// <summary>
        /// Длина прокрутки ползунка.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Длина прокрутки ползунка")
        ]
        public float ScrollBarPathLength
        {
            get
            {
                return liteHScrolBar1.ScrollBarPathLength;
            }
        }

        /// <summary>
        /// Длина ползунка.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Длина ползунка")
        ]
        public float CrawlLength
        {
            get
            {
				return liteHScrolBar1.CurrentCrawlerLength;
            }
        }

        /// <summary>
        /// Элемент управления - ползунок.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Элемент управления - ползунок")
        ]
        public Cerebrum.Direct3D.Forms.Control CrawlControl
        {
            get
            {
                return liteHScrolBar1.CrawlerControl;
            }
        }

        /// <summary>
        /// Кнопка Up.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Кнопка Up")
        ]
        public Cerebrum.Direct3D.Forms.ImageButton UpButton
        {
            get
            {
                return btnLeft;
            }
        }

        /// <summary>
        /// Кнопка Down.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Кнопка Down")
        ]
        public Cerebrum.Direct3D.Forms.ImageButton DownButton
        {
            get
            {
                return btnRight;
            }
        }
        #endregion
    }
}
